package com.enhe.gck.utils;

import com.enhe.gck.communal.PublicReturn;
import com.kuangkie.hydrocarbon.api.MultilingualContentGetter;
import com.kuangkie.hydrocarbon.api.MultilingualTransRegister;
import org.springframework.data.repository.init.ResourceReader;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.HashSet;

@Component
public class GCKMultilingualContent implements MultilingualContentGetter {
    static {
        MultilingualTransRegister.register(null, new GCKMultilingualContent());
    }

    @Override
    public Collection<String> getContents() {
        Collection<String> contents = new HashSet<>();
        for (PublicReturn pub :PublicReturn.values()){
            contents.add(pub.getName());
        }

        InputStream inputStream = ResourceReader.class.getClassLoader().getResourceAsStream("file/translate-app.txt");
        if (inputStream != null) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
            try  {
                String line;
                while ((line = reader.readLine()) != null) {
                    contents.add(line);
                }
            } catch (Exception e) {
            }finally {
                try{
                    if(inputStream!=null){
                        inputStream.close();
                    }
                }catch (Exception e){

                }
                try{
                    if(reader!=null){
                        reader.close();
                    }
                }catch (Exception e){

                }
            }
        }
        return contents;
    }
}
